package LC;

/**
 * @ClassName LC437
 * @Description: TODO
 * @Author hl
 * @Date 2020/6/6
 * @Version V1.0
 **/
public class LC437 {

    public int pathSum(TreeNode root, int sum) {
     if(root==null){
         return 0;
     }
     int result=seach(root,sum);
     result+=pathSum(root.left,sum);
     result+=pathSum(root.right,sum);
     return result;

    }

    public int seach(TreeNode root, int sum) {
        if(root==null){
            return  0;
        }
        sum=sum-root.val;
       int result=sum==0?1:0;
       result+=seach(root.left,sum)+seach(root.right,sum);
       return  result;
    }
}

